package com.haiwei.poi.word.manager;

import com.haiwei.poi.word.bean.HaiweiBeanUtil;
import com.haiwei.poi.word.common.HaiweiDocumentGenerator;
import com.haiwei.poi.word.poi.HaiweiXWPFDocumentUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * word 生成器.
 *
 * @date: 2022-06-24
 * @version: 1.0
 * @author: karry@haiwei.com
 */
@Slf4j
public class HaiweiWordExporteUtil {
    
    @Data
    @AllArgsConstructor
    static class Item1{
        private String name = "鼠标";
        private String type = "电子类";
        private String time = "2018/8/26";
    }
    
    @Data
    @AllArgsConstructor
    static class Order1{
        private String name = "订单名称";
        private String no = "订单编号";
        private List<Item1> items;
    
    }
    
    public static void main(String[] args) {
        try {
            // 获取document
            final XWPFDocument document = HaiweiDocumentGenerator
                    .build(new File("C:\\Users\\admin\\Desktop\\22\\33.docx"));
    
            // 数据构建
            List<Item1> items1 = new ArrayList<>();
            items1.add(new Item1("鼠标11","电子类11","2018/8/11"));
            items1.add(new Item1("鼠标12","电子类12","2018/8/12"));
    
            List<Item1> items2 = new ArrayList<>();
            items2.add(new Item1("鼠标21","电子类21","2018/8/21"));
            items2.add(new Item1("鼠标22","电子类22","2018/8/22"));
    
            Order1 order1 = new Order1("特仑苏1","N0001",items1);
            Order1 order2 = new Order1("特仑苏2","N0002",items2);
            List<Order1> orders = new ArrayList<>();
            orders.add(order1);
            orders.add(order2);
            HaiweiBeanUtil.setBean(orders,"orders");
            HaiweiBeanUtil.setString("N0001文档编号","文档编号");
            HaiweiBeanUtil.print();
            
            // 设置回调函数
            HaiweiBeanUtil.setCallBackCache(null);
    
            //解析文档
            HaiweiXWPFDocumentUtil.parse(document);
    
            // 生成文件
            final File file = new File("C:\\Users\\admin\\Desktop\\22\\3333.docx");
            HaiweiDocumentGenerator.toFile(document,file);
            System.out.println(file.getAbsolutePath());
            
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    
    
    
}
